
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 1027
 * @Author : WangRuoyu 
 * @Date : 2023/5/27 10:29
 */

#include "iostream"
#include "vector"

using namespace std;

class Solution {
public:
    int longestArithSeqLength(vector<int> &nums) {
        int f[nums.size() + 1][1001];

        for (int i = 0; i <= nums.size(); ++i) {
            for (int j = 0; j < 1001; ++j) {
                f[i][j] = 1;
            }
        }

        int res = 1;
        for (int i = 1; i <= nums.size(); ++i) {
            for (int j = 1; j < i; ++j) {
                int d = nums[i - 1] - nums[j - 1];
                f[i][d + 500] = max(f[i][d + 500], f[j][d + 500] + 1);
                res = max(res, f[i][d + 500]);
            }
        }

        return res;
    }
};

int main() {
    Solution sl;
    vector<int> nums = {20,1,15,3,10,5,8};
    printf("%d\n", sl.longestArithSeqLength(nums));
    return 0;
}